package snapex.core.mapper.ext;

import java.sql.Date;

import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

public class ExpenseSqlProvider implements ProviderMethodResolver {
	
   public static String calcTotalAmount(String expenseId) {
		
		StringBuilder sql = new StringBuilder();
		sql.append("with t as (select sum(amount) as total from expense_detail where expense_id=#{expenseId}) ")
		.append("update expense set total_amount = (select total from t) where expense_id=#{expenseId}")
		;				
		
		return sql.toString();
	}

   public static String updateExpenseStatus(String expenseId, Integer status, Date submittedDate) {	   
		return "update expense set status = #{status}, submitted_date = #{submittedDate} where expense_id = #{expenseId}";
  }
   
   public static String updateExpenseDetailStatus(String expenseId, Integer status) {	   
		return "update expense_detail set status = #{status} where expense_id=#{expenseId}";
   }
}
